<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="include/header.jsp" %>
<head>
    <script  src="${pageContext.request.contextPath}/res/js/fore/fore_productBuyCar.js"></script>
    <link href="${pageContext.request.contextPath}/res/css/fore/fore_productBuyCarPage.css" rel="stylesheet"/>
    <title>地址管理</title>
    <script>
        $(function () {
            $('#btn-ok').click(function () {
                $.ajax({
                    url: "${pageContext.request.contextPath}/orderItem/" + $("#order_id_hidden").val(),
                    type: "DELETE",
                    data: null,
                    dataType: "json",
                    success: function (data) {
                        if (data.success !== true) {
                            alert("购物车商品删除异常，请稍候再试！");
                        }
                        location.href = "/tmall/cart";
                    },
                    beforeSend: function () {

                    },
                    error: function () {
                        alert("购物车产品删除异常，请稍后再试！");
                        location.href = "/tmall/cart";
                    }
                });
            });
        });

        function removeItem(orderItem_id) {
            if (isNaN(orderItem_id) || orderItem_id === null) {
                return;
            }
            $("#order_id_hidden").val(orderItem_id);
            $('#modalDiv').modal();
        }
    </script>
</head>
<body>
<nav>
    <%@ include file="include/navigator.jsp" %>
    <div class="header">
        <div id="mallLogo">
            <a href="${pageContext.request.contextPath}"><img
                    src="${pageContext.request.contextPath}/res/images/fore/WebsiteImage/tmallLogoA.png"><span
                    class="span_tmallBuyCar">地址管理</span></a>
        </div>

    </div>
</nav>
<div class="content">
    <c:choose>
        <c:when test="${fn:length(requestScope.adressDetails)<=0}">
            <div id="empty">
                <h2>您的地址管理还是空的，赶紧添加吧！您可以：</h2>
                <ul>
                    <li><a href="${pageContext.request.contextPath}/addressList">添加</a></li>
                </ul>
            </div>
        </c:when>
        <c:otherwise>
            <div id="J_FilterBar">
                <ul id="J_CartSwitch">
                    <li>
                        <a href="${pageContext.request.contextPath}/addressList" class="J_MakePoint">
                            <em>添加地址</em>
                                <%--                            <span class="number">${requestScope.totalPage}</span>--%>
                        </a>
                    </li>
                </ul>

                <div class="wrap-line">
                    <div class="floater"></div>
                </div>
            </div>
            <table id="J_CartMain">
                <thead>
                <tr>
                    <th width="474px" class="productInfo_th"><span>地址</span></th>
                    <th width="120px" ><span>邮政编码</span></th>
                    <th width="120px" style="color: #0F1322"><span>收货人</span></th>
                    <th width="120px" style="color: #0F1322"><span>手机号码</span></th>
                    <th width="120px"><span>操作</span></th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${requestScope.adressDetails}" var="adressDetail">
                    <tr class="orderItem_info">
                        <td ><span>

                            <c:if test="${not empty requestScope.order_item_list}">
                                <a href="${pageContext.request.contextPath}/address/create/${adressDetail.id}/${requestScope.order_item_list}">${adressDetail.detailAddress}</a>
                            </c:if>
                            <c:if test="${not empty requestScope.pid}">
                                <a href="${pageContext.request.contextPath}/address/create/${adressDetail.id}/${requestScope.pid}/${requestScope.pNum}">${adressDetail.detailAddress}</a>
                            </c:if>
                            <c:if test="${empty requestScope.pid && empty requestScope.order_item_list }">
                                <span style="margin-left: 30px">
                                        ${adressDetail.detailAddress}
                                </span>
                            </c:if>
                        </span></td>
                        <td >
                            <span class="orderItem_product_realPrice" style="color: #0F1322">${adressDetail.post}</span>
                        </td>
                        <td >
                            <span class="orderItem_product_realPrice" style="color: #0F1322">${adressDetail.receiver}</span>
                        </td>
                        <td >
                            <span class="orderItem_product_realPrice" style="color: #0F1322">${adressDetail.phone}</span>
                        </td>
                        <td><a href="javascript:void(0)" onclick="deleteAddress('${adressDetail.id}')"
                               class="remove_order" style="color: red">删除</a></td>

                    </tr>
                </c:forEach>
                </tbody>
            </table>

        </c:otherwise>
    </c:choose>
</div>
<script>
    function deleteAddress(id){
        $.ajax({
            url: "addressDetail/delete",
            type: "get",
            data: {
                "id": id,
            },
            traditional: true,
            success: function (data) {
                if (data.success) {
                    location.href = "/tmall" + data.url;
                    return true;
                } else {
                    alert("地址删除失败，请稍后再试！");
                    location.reload(true);
                }
            },
            beforeSend: function () {
            },
            error: function () {
                alert("地址删除失败，请稍后再试！");
                location.reload(true);
            }
        });
    }

</script>

<%@include file="include/footer_two.jsp" %>
<%@include file="include/footer.jsp" %>
</body>
